package com.qf.service.impl;

import com.qf.service.AuthService;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
public class AuthServiceImpl implements AuthService {
    @Override
    public String findJwtTokenFromCookie(ServerHttpRequest request, String cookieName) {
        //获取所有的cookie
        MultiValueMap<String, HttpCookie> cookies = request.getCookies();

        //获取cookie中的 jwtToken
        HttpCookie cookie = cookies.getFirst(cookieName);

        //如果不为null， 则返回 cookie值
        if(cookie != null) {
            return  cookie.getValue();
        }

        return null;
    }
}
